$(function() {
	//子产品起息日
	WASP_WIDGET.triggerDateRangeStyle("q-expectPayDate");
	
	WASP_WIDGET.triggerDateRangeStyle("q-bnsDate");
	//注册清空事件
    WASP_WIDGET.registerResetClearEvent();
	
	//triggerSelectOnSecurId('q-securId');
	
	$('#q-feeType').select2({placeholder: '类型'});
	
	$('#q-isPay').select2({placeholder: '是否支付'});
	
	//部门
	WASP_WIDGET.triggerSelectOnDeptId("q-deptId");
	//项目经理
	WASP_WIDGET.triggerSelectOnEmpId("#q-mgrId");
	
	chosenStyle();
});

//连接跳转过来也要选中样式
function chosenStyle(){
	//debugger;
	var prdFy = window.parent.document.getElementById("prdFy");
	window.parent.pageApp.changeLocation($(prdFy));
//    $(prdFy).addClass('active');
//    //var estimate = window.parent.document.getElementsByClassName('estimate');
//    var khqy = window.parent.document.getElementById("khqy");
//    $(khqy).removeClass('active');
}

//条件查询
function queryByCondtion(flag) {
	var prjsName = $.trim($("#q-prjsName").val());
	var outCode = $.trim($("#q-outCode").val());
	var subFundsName = $.trim($("#q-subFundsName").val());
    var fundCode = $.trim($("#q-fundCode").val());
    var feeName = $.trim($("#q-feeName").val());
    var expectPayDateBegin = $("#q-expectPayDate").getDateRangeValue()[0];
    var expectPayDateEnd = $("#q-expectPayDate").getDateRangeValue()[1];
    var bnsDateBegin = $("#q-bnsDate").getDateRangeValue()[0];
    var bnsDateEnd = $("#q-bnsDate").getDateRangeValue()[1];
    var isPay = $("#q-isPay").val();
    var feeType = $("#q-feeType").val();
    var deptId = $("#q-deptId").val();
	var mgrId = $("#q-mgrId").val();
	if(deptId == null){
		deptId = '';
	}
	if(mgrId == null){
		mgrId = '';	
	}
    
	var postData = $("#prdFeeYieldList").jqGrid("getGridParam", "postData");
	$.extend(postData,{
		'sp[prjsName]':prjsName,
    	'sp[outCode]':outCode,
    	'sp[subFundsName]':subFundsName,
    	'sp[fundCode]':fundCode,
    	'sp[feeName]':feeName,
    	'sp[expectPayDateBegin]':expectPayDateBegin,
    	'sp[expectPayDateEnd]':expectPayDateEnd,
    	'sp[bnsDateBegin]':bnsDateBegin,
    	'sp[bnsDateEnd]':bnsDateEnd,
    	'sp[feeType]':feeType,
    	'sp[isPay]':isPay,
    	'sp[deptId]':deptId,
        'sp[mgrId]':mgrId
	});
    if (flag) {
    	$("#prdFeeYieldList").trigger("reloadGrid",[{page:1}]);//重新载入Grid表格
    } else {
    	$("#prdFeeYieldList").trigger("reloadGrid");//重新载入Grid表格
    }
}

//查询数据-待办
function queryByCondtionForCustomerEquity(json) {
	
    var obj = eval('(' + json + ')');
	var beginDate = obj.beginDate;
	var endDate = obj.endDate;
	var feeType = obj.feeType;
	var dateType = obj.dateType;
	
	$("#q-feeType").val(feeType);
	
	$('#q-feeType').select2({placeholder: '类型'});
	
	if(dateType == '1'){
		$("#q-expectPayDate").val(moment(beginDate, "YYYYMMDD").format('YYYY/MM/DD') +' - ' + moment(endDate, "YYYYMMDD").format('YYYY/MM/DD'));//默认显示5个工作日
	}else{
		$("#q-bnsDate").val(moment(beginDate, "YYYYMMDD").format('YYYY/MM/DD') +' - ' + moment(endDate, "YYYYMMDD").format('YYYY/MM/DD'));//默认显示5个工作日
	}
	
	var arriveBeginDate = $("#q-txtArriveDate").getDateRangeValue()[0].replace(/-/g,"");
	var arriveEndDate = $("#q-txtArriveDate").getDateRangeValue()[1].replace(/-/g,"");
	
	var prjsName = '';
	var outCode = '';
	var subFundsName = '';
    var fundCode = '';
    var feeName = '';
    var expectPayDateBegin = '';
    var expectPayDateEnd = '';
    var bnsDateBegin = '';
    var bnsDateEnd = '';
    if(dateType == '1'){
    	expectPayDateBegin = $("#q-expectPayDate").getDateRangeValue()[0];
        expectPayDateEnd = $("#q-expectPayDate").getDateRangeValue()[1];
	}else{
		bnsDateBegin = $("#q-bnsDate").getDateRangeValue()[0];
	    bnsDateEnd = $("#q-bnsDate").getDateRangeValue()[1];
	}
    var isPay = '';
    var feeType = $("#q-feeType").val();
    var deptId = '';
	var mgrId = '';
    
	var postData = $("#prdFeeYieldList").jqGrid("getGridParam", "postData");
	$.extend(postData,{
		'sp[prjsName]':prjsName,
    	'sp[outCode]':outCode,
    	'sp[subFundsName]':subFundsName,
    	'sp[fundCode]':fundCode,
    	'sp[feeName]':feeName,
    	'sp[expectPayDateBegin]':expectPayDateBegin,
    	'sp[expectPayDateEnd]':expectPayDateEnd,
    	'sp[bnsDateBegin]':bnsDateBegin,
    	'sp[bnsDateEnd]':bnsDateEnd,
    	'sp[feeType]':feeType,
    	'sp[isPay]':isPay,
    	'sp[deptId]':deptId,
        'sp[mgrId]':mgrId
	});
	$("#prdFeeYieldList").trigger("reloadGrid",[{page:1}]);
}

//查询标的简称
function triggerSelectOnSecurId(securId) {
	var _placeholder = $('#' + securId).attr("placeholder");
	if (_placeholder == null || _placeholder == '' || _placeholder == 'undefind') {
		_placeholder = "标的简称";
	}
	$('#' + securId).select2({
		language:"zh-CN",
		placeholder : _placeholder,
		multiple : false,
		ajax : {
			url : PATH_PREFIX + "querySecurId.do",
			type : "POST",
			data : function(params) {
				var query;
				if (params.term == null || params.term == '' || params.term == 'undefind') {
					query = {
						prdCode : '',
						securId : "",
						limit : 10
					};
				} else {
					query = {
						prdCode : '',
						securId : params.term,
						limit : 10
					};
				}
				return query;
			},
			dataType : "json",
			processResults : function(data) {
			
				var results = $.map(data, function(obj) {
					return {
						id : obj.securNo,
						text : obj.securId
					}
				});
				return {
					results : results
				};
			}
		},
		cache : true,
		delay : 3000,
		templateSelection : function(obj) {
			console.info(obj);
			return $('<span data-html="true" >' + obj.text + '</span>').tooltip();
		}
	});
}

